package com.yfp.client.service.impl;

import com.yfp.client.domain.MachineClientLiveness;
import com.yfp.client.domain.dto.ClientLivenessDTO;
import com.yfp.client.mapper.MachineClientLivenessMapper;
import com.yfp.client.service.MachineClientLivenessService;
import com.yfp.client.util.SecurityUtils;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;

/**
 * 
 * @version 1.0
 * @date 2024-05-28 10:51
 */
@Service
@Slf4j
public class MachineClientLivenessServiceImpl implements MachineClientLivenessService {
    @Resource
    private MachineClientLivenessMapper machineClientLivenessMapper;


    /**
     * 统计活跃度
     * @param clientLivenessDTO
     * @return
     */
    @Override
    @Transactional
    public void activesTatistics(ClientLivenessDTO clientLivenessDTO) {
        String temporarySign = clientLivenessDTO.getTemporarySign();
        MachineClientLiveness liveness = new MachineClientLiveness();
        if (temporarySign == null) {
            String userId = SecurityUtils.getClientId();
            liveness.setClientId(userId);
        } else {
            liveness.setTemporarySign(temporarySign);
        }
        liveness.setMachineId(clientLivenessDTO.getMachineId());
        liveness.setCreateTime(new Timestamp(System.currentTimeMillis()));
        machineClientLivenessMapper.insert(liveness);
    }
}
